//
//  SXBaseViewController.swift
//  微博09项目
//
//  Created by mac on 15/9/1.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

class SXBaseViewController: UITableViewController {
    /// 用户登录的标记
    
    ////    var userLogon = UserAccount.loadUserAccount()?.access_token != nil
  //  var userLogin = false
    var userLogon = UserAccountViewModel.shareUserAccount.userLogon
    var  LoginView:SXLoginView?
    //这里不能用懒加载，因为使用懒加载，会在用户登陆成功之后，视图任然被创建，虽然不影响程序的执行，但是会消耗内存
//   lazy var iconView : SXLoginView = SXLoginView()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
       
       
    }
 
    override func loadView() {
        userLogon ? super.loadView() :setupVistorView()
    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
       
    }
    
   private func setupVistorView(){
        LoginView = SXLoginView()
        // LoginView?.delegate = self
        view = LoginView
        view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
       // view.backgroundColor = UIColor.orangeColor()
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginViewWillRegister")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginViewWillLogin")
        LoginView?.registerButton.addTarget(self, action: "visitorLoginViewWillRegister", forControlEvents: UIControlEvents.TouchUpInside)
        LoginView?.loginButton.addTarget(self, action: "visitorLoginViewWillLogin", forControlEvents: UIControlEvents.TouchUpInside)
        
        
        
    }
    func visitorLoginViewWillRegister(){
        
        print("注册")
    }
    func visitorLoginViewWillLogin(){
       let nav = UINavigationController(rootViewController: SXOauthController())
        
        presentViewController(nav, animated:true, completion: nil)
    }

  
}
